import React from 'react';
import { inject, observer } from 'mobx-react';
import { withRouter } from 'react-router-dom';

import { Icon, Tools, Modal, Toast } from 'weaver-mobile';

const getLabel = Tools.getLabel;
const alert = Modal.alert;

@inject('blogShareToMeStore')
@withRouter
@observer
export default class ShareToMeTool extends React.Component {
  constructor(props) {
		super(props);
		this.apply = this.apply.bind(this);
	}

  apply = (event) => {
    event.stopPropagation(); // 阻止事件冒泡
    const { blogShareToMeStore : { attentionOpt } } = this.props;
    let {attentionStatus, islower, userId, callback} = this.props;
    if(attentionStatus === '1' || attentionStatus === '2') {
        alert(getLabel(129256, '确定要取消吗?'),'',[
            {text: getLabel(31129, '取消')},
            {text: getLabel(33703, '确认'), onPress: () => {
                attentionOpt({attentionStatus, islower, userId,type:'share', weiBoPage:'1'},callback)
            }}
          ])

      }else {
        attentionOpt({attentionStatus, islower, userId,type:'share', weiBoPage:'1'},callback)
      } 
  }

  render() {
   /**
		 * attentionStatus
		 1表示单向关注，按钮显示 取消关注。
		 2表示双向关注，按钮显示 取消关注。
		 3表示没有关注关系，且不是上下级关系。 按钮显示 申请关注。
		 4表示没有关注关系，且不是上下级关系，且已发送申请。按钮显示 已发送申请。
		 5表示没有关注关系，且是上下级关系。按钮显示 添加关注。
		 isreceive==0,不允许申请关注
		 */
    let text,type,
        func = this.apply,
        className = 'text-info active',
        { isreceive, attentionStatus } = this.props;
     if(attentionStatus=='3'||attentionStatus=='5'){
        return "";
     }else if(attentionStatus=='6') {
         text=getLabel(514285,'特别关注') ;type='special-concern-1' ;className='text-info';
     }else{


        text='已关注';type='add-attention';className='text-info';
        //{icon: "icon-blog-CancelConcern", text: getLabel('26938',"取消关注")}
     }
    return (
      (isreceive === '0' && attentionStatus === (this.props.type === 'myfans' ? '2' : '3')) 
			? <span />
			: <div className={className}><Icon type={type} size='xxs'/><span style={{marginLeft: 6}}>{text}</span></div>
    )
  }
}